<!--
function clsChkRegister ( form, objSelf )
{
	if ( objSelf == null ) objSelf = 'clsChkRegister';
	this.objSelf = objSelf;
	this.passed = false;
	this.objForm = document.getElementById (form);
	this.className = [ 'boxNormal', 'boxError', 'boxOK', 'boxWaiting' ];
	this.checkItems = [ "Username", "Nickname", "Password", "PasswordConfirm", "Question", "Answer", "Email", "Code" ];
	this.currentUser = null;
	this.checkScript = '/check';

	this.messages = {
		'Username'				: "<font color='#FF0000'>（字符数在4-20之间）</font'>",
		'Nickname'				: "<font color='#FF0000'>（字符数在4-20之间）</font>",
		'Password'				: "<font color='#FF0000'>（长度为6-20个字符）</font>",
		'PasswordConfirm'		: "<font color='#FF0000'>再次输入密码。</font>",
		'Email'					: "<font color='#FF0000'>请在此输入您的真实邮箱</font>",
		'Question'				: "<font color='#FFFFFF'>如不修改请留空</fomt>",
		'Answer'	 				: '如不修改请留空',
		'Code'					: "<font color='#FF0000'>输入图中的数字，看不清点击图片更换。</font>",
		'PasswordOld'			: '请输入您当前的登录密码。',
		'Dump'					: ''
	};

	// 提交注册信息时验证
	this.checkForm = function ()
	{
		this.passed = true;
		for ( var i = 0; i < this.checkItems.length; i ++ )
		{
			obj = document.getElementById ( "tip" + this.checkItems[i] );
			if ( obj.className != this.className[2] )
			{
				var check = eval ( "this.check" + this.checkItems[i] + "()" );
				if ( check == 'checking' )
				{
					this.passed = false;
				}
				else
				{
					this.passed = this.passed && check;
				}
			}
		}
		return this.passed;
	}

	// 显示所有提示
	this.showAllTips = function ()
	{
		for ( var i in this.checkItems )
		{
			var obj;
			if ( obj = document.getElementById ( 'tip' + this.checkItems[i] ) )
			{
				obj.innerHTML = eval ( "this.messages." + this.checkItems[i] );
			}
		}
	}

	this.showTip = function ( chkItem, tipType, message )
	{
		var obj;
		if ( obj = document.getElementById ( 'tip' + chkItem ) )
		{
			if ( tipType == null ) tipType = 0;
			if ( message == null ) message = eval ( "this.messages." + chkItem );
			obj.style.display = "block";
			if ( tipType > 0 || obj.className != this.className[2] || obj.className == '' )
			{
				obj.innerHTML = message;
				obj.className = this.className[tipType];
			}
		}
	}
	
	this.hideTip = function ( chkItem )
	{
		var obj;
		if ( obj = document.getElementById ( 'tip' + chkItem ) )
		{
			if ( obj.className != this.className[2] )
			{
				obj.style.display = "none";
			}
		}
	}

	/****** 检验部分 ******/

	// 检查用户名
	this.checkUsername = function ( checkSystem )
	{
		var message = '';
		if ( checkSystem == null ) checkSystem = true;
		if ( this.objForm.username.value.length == 0 )
		{
			message = "<font color='#FF0000'>请填写用户名</font>";
		}
		else if ( this.objForm.username.value.indexOf (' ') >= 0 || this.objForm.username.value.indexOf ('\\') >= 0 || this.objForm.username.value.indexOf ('\'') >= 0 || this.objForm.username.value.indexOf ('\"') >= 0 )
		{
			message = "<font color='#FF0000'>用户名包含非法字符</font>";
		}		
		if ( message != '' )
		{
			this.showTip ( 'Username', 1, message );
			return false;
		}
		else if ( checkSystem )
		{
			this.checkUsernameSystem ();
			return 'checking';
		}
		return true;
	}

	// Ajax 检查用户名
	this.checkUsernameSystem = function ()
	{
		this.showTip ( 'Username', 3, '正在检测用户名...' );
		var registerAjax = new Ajax ( this.checkScript, "act=user&username=" + escape ( this.objForm.username.value ), this.callbackCheckUsername, eval(this.objSelf) );
		registerAjax.get ();
	}

	// 检查用户名回调函数
	this.callbackCheckUsername = function ( ret, obj )
	{
		if ( ret == 'OK' )
		{
			obj.showTip ( 'Username', 3, "您填写的用户名可以成功注册" );
			return true;
		}
		else if ( ret != '' )
		{
			obj.showTip ( 'Username', 1, "<font color='#FF0000'>您填写的用户名已经被使用</font>" );
			return false;
		}
		else
		{
			obj.hideTip ( 'Username' );
		}
	}

	// 检查昵称
	this.checkNickname = function ( checkSystem )
	{
		var message = '';
		if ( checkSystem == null ) checkSystem = true;
		if ( this.objForm.nickname.value.length == 0 )
		{
			message = "<font color='#FF0000'>请填写昵称</font>";
		}
		else if ( this.objForm.nickname.value.indexOf (' ') >= 0 || this.objForm.nickname.value.indexOf ('\\') >= 0 || this.objForm.nickname.value.indexOf ('\'') >= 0 || this.objForm.nickname.value.indexOf ('\"') >= 0 )
		{
			message = "<font color='#FF0000'>昵称包含非法字符</font>";
		}		
		if ( message != '' )
		{
			this.showTip ( 'Nickname', 1, message );
			return false;
		}
		else if ( checkSystem )
		{
			this.checkNicknameSystem ();
			return 'checking';
		}
		return true;
	}

	// Ajax 检查昵称
	this.checkNicknameSystem = function ()
	{
		this.showTip ( 'Nickname', 3, '正在检测昵称...' );
		var registerAjax = new Ajax ( this.checkScript, "act=nickname&nickname=" + escape ( this.objForm.nickname.value ), this.callbackCheckNickname, eval(this.objSelf) );
		registerAjax.get ();
	}

	// 检查昵称回调函数
	this.callbackCheckNickname = function ( ret, obj )
	{
		if ( ret == 'OK' )
		{
			obj.showTip ( 'Nickname', 3, "您填写的昵称可以成功注册" );
			return true;
		}
		else if ( ret != '' )
		{
			obj.showTip ( 'Nickname', 1, "<font color='#FF0000'>您填写的昵称已经被使用</font>" );
			return false;
		}
		else
		{
			obj.hideTip ( 'Nickname' );
		}
	}

	// 检查原密码
	this.checkPasswordOld = function ( checkSystem )
	{
		var message = '';
		if ( this.objForm.passwordold.value.length < 6 || this.objForm.passwordold.value.length > 20 )
		{
			message = "<font color='#FF0000'>密码长度必须为 6 - 20 字符</font>";
		}
		if ( message != '' )
		{
			this.showTip ( 'PasswordOld', 1, message );
			return false;
		}
		else
		{
			this.showTip ( 'PasswordOld', 3, "<font color='#FF0000'>等待验证</font>" );
			return true;
		}
	}

	// 检查密码
	this.checkPassword = function ()
	{
		var message = '';
		if ( this.objForm.password.value.length < 6 || this.objForm.password.value.length > 20 )
		{
			message = "<font color='#FF0000'>密码长度必须为6-20字符</font>";
		}
		else if ( this.objForm.password.value != '' && this.objForm.password.value == this.objForm.username.value )
		{
			message = "<font color='#FF0000'>为了安全，密码不要与用户名相同</font>";
		}
		/*
		else if ( get_strong_level ( this.objForm.password.value, 6 ) < 2 )
		{
			message = '您的密码强度太弱';
		}
		*/

		if ( message != '' )
		{
			this.showTip ( 'Password', 1, message );
			return false;
		}
		else
		{
			this.showTip ( 'Password', 3, "填写正确" );
			return true;
		}	
	}

	// 检查密码确认
	this.checkPasswordConfirm = function ()
	{
		var message = '';
		if ( this.objForm.passwordcfm.value != this.objForm.password.value )
		{
			message = "<font color='#FF0000'>两次密码不一致, 请重新填写</font>";
		}
		else if ( this.objForm.password.value == '' )
		{
			message = "<font color='#FF0000'>请填写密码</font>";
		}
		
		if ( message != '' )
		{
			this.showTip ( 'PasswordConfirm', 1, message );
			return false;
		}
		else
		{
			this.showTip ( 'PasswordConfirm', 3, "填写正确" );
			return true;
		}
	}

	this.checkEmail = function ( username, checkSystem )
	{
		var message = '';
		checkSystem = checkSystem != null ? checkSystem : true;
		if ( this.objForm.email.value.length == 0 )
		{
			message = "请填写您的邮箱地址";
		}
		if ( message != '' )
		{
			this.showTip ( 'Email', 1, message );
			return false;
		}
		else if ( checkSystem )
		{
			this.checkEmailSystem ( username );
			return 'checking';
		}
		return true;
	}

	this.checkEmailSystem = function ( username )
	{
		if ( username == null ) username = this.currentUser;
		this.showTip ( 'Email', 3, '正在检测邮箱地址...' );
		var registerAjax = new Ajax ( this.checkScript, "act=email&email=" + escape ( this.objForm.email.value ) + "&username=" + escape ( username ), this.callbackCheckEmail, eval(this.objSelf) );
		registerAjax.get ();
	}

	this.callbackCheckEmail = function ( ret, obj )
	{
		if ( ret == 'OK' )
		{
			obj.showTip ( 'Email', 3, '填写正确' );
			return true;
		}
		else if ( ret != '' )
		{
			obj.showTip ( 'Email', 1, '<font color="#FF0000">Email地址无效，请重新输入</font>' );
			return false;
		}
		else
		{
			obj.hideTip ( 'Email' );
		}
	}

	this.checkQuestion = function ()
	{
		var message = '';
		if ( this.objForm.user_question.value == '' )
		{
			message = '如不修改请留空';
			ret = true;
		}
		else
		{
			message = '填写正确';
			ret = true;
		}

		this.showTip ( 'Question', ret ? 2 : 1, message );
		return ret;
	}

	this.checkAnswer = function ()
	{
		var message = '';
		if ( this.objForm.user_answer.value == '' )
		{
			message = '如不修改请留空';
			ret = true;
		}
		else if ( this.objForm.user_answer.value == this.objForm.user_question.value )
		{
			message = '为了您的账号安全，密码提示答案请不要与问题相同';
			ret = false;
		}
		else
		{
			message = '填写正确';
			ret = true;
		}

		this.showTip ( 'Answer', ret ? 2 : 1, message );
		return ret;
	}

	this.checkCode = function ()
	{
		var Code = GetCookie ( 'verifyCode' );
		if ( this.objForm.code.value.toUpperCase () != Code.toUpperCase () )
		{
			this.showTip ( 'Code', 1, "<font color='#FF0000'>验证码不正确, 请检查并重新填写</font>" );
			return false;
		}
		else
		{
			this.showTip ( 'Code', 3, "填写正确" );
			return true;
		}
	}
}

// 检查密码强度
function check_password_strong ( password )
{
	var strong = get_strong_level ( password, 6 );

	var objS1 = document.getElementById ( 'password_strong_1' );
	var objS2 = document.getElementById ( 'password_strong_2' );
	var objS3 = document.getElementById ( 'password_strong_3' );

	if ( strong == 1 )
	{
		objS1.className = 'pass_password_s1';
		objS2.className = 'pass_password_s0';
		objS3.className = 'pass_password_s0';
	}
	else if ( strong == 2 )
	{
		objS1.className = 'pass_password_s2';
		objS2.className = 'pass_password_s2';
		objS3.className = 'pass_password_s0';
	}
	else if ( strong >= 3 )
	{
		objS1.className = 'pass_password_s3';
		objS2.className = 'pass_password_s3';
		objS3.className = 'pass_password_s3';
	}
	else
	{
		objS1.className = 'pass_password_s0';
		objS2.className = 'pass_password_s0';
		objS3.className = 'pass_password_s0';
	}
}

function get_strong_level ( string, minLength )
{
	if ( minLength == null ) minLength = 1;
	if ( string.length < minLength )
	{
		return 0;
	}

	var ls = 0;
	if ( string.match(/[a-z]/ig ) )
	{
		ls ++;
	}
	if ( string.match(/[0-9]/ig ) )
	{
		ls ++;
	}
	if ( string.match(/(.[^a-z0-9])/ig ) )
	{
		ls ++;
	}
	if ( string.length >= 10 )
	{
		ls ++;
	}

	var firstChar = string.substr ( 0, 1 );
	var repeat = 1;
	for ( var i = 1; i < string.length; i ++ )
	{
		if ( string.substr ( i, 1 ) == firstChar )
		{
			repeat ++;
		}
		else
		{
			break;
		}
	}
	if ( string.length == repeat )
	{
		ls --;
	}

	var seq = '01234567890abcdefghijklmnopqrstuvwxyz';
	if ( seq.indexOf ( string.toLowerCase () ) >= 0 )
	{
		ls --;
	}

	ls = Math.max ( ls, 1 );

	return ls;
}

// 获取手机验证密钥
function get_phone_code ( form, confirmMsg )
{
	if ( typeof ( form ) == 'string' ) form = $ ( form );
	if ( !check_phone ( form ) ) return false;
	if ( confirmMsg == null ) confirmMsg = '请确认您的手机号码填写无误，点击“确定”系统将发送验证密钥到您指定的手机号码！';

	var phone = form.bind_value.value;
	if ( confirm ( confirmMsg ) )
	{
		var registerAjax = new Ajax ( '/bind', 'act=get_phone_code&phone=' + phone, callback_get_phone_code, phone );
		registerAjax.get ();
	}
}

function bind_set_step ( step )
{
	if ( step == 'code' )
	{
		var form = $('formBind');
		if ( !check_phone ( form ) ) return false;
		$('bindingPhoneNumber').innerHTML = form.bind_value.value;
		var arrDisplay = [ 'none', '', 'none' ];
	}
	else if ( step == 'cancel' )
	{
		var arrDisplay = [ 'none', 'none', '' ];
	}
	else
	{
		var arrDisplay = [ '', 'none', 'none' ];
	}

	$('stepSetPhone').style.display = arrDisplay[0];
	$('stepSetCode').style.display = arrDisplay[1];
	$('stepCancelPhone').style.display = arrDisplay[2];
}

function check_phone ( form )
{
	var phone = form.bind_value.value;
	if ( phone == '' )
	{
		showMessage ( '请填写手机号码！' );
		form.bind_value.focus ();
		return false;
	}
	if ( !phone.match ( /^[0-9]{11}$/ ) )
	{
		showMessage ( '您的手机号码格式无效，请重新填写！' );
		form.bind_value.select ();
		return false;
	}
	return true;
}

function check_phone_code ( form )
{
	var phoneCode = form.bind_code.value;
	if ( phoneCode == '' )
	{
		showMessage ( '请填写验证密钥！如果您尚未获取或者遗忘了验证密钥，请点击“重新获取密钥”按钮获取！' );
		form.bind_code.focus ();
		return false;
	}
	if ( !phoneCode.match ( /^[a-zA-Z0-9]{6}$/ ) )
	{
		showMessage ( '您的验证密钥格式无效，请重新填写！\n如果您尚未获取或者遗忘了验证密钥，请点击“重新获取密钥”按钮获取！' );
		form.bind_code.select ();
		return false;
	}
	return true;
}

function callback_get_phone_code ( ret, phone )
{
	if ( ret == 'OK' )
	{
		bind_set_step ( 'code' );
		showMessage ( '验证密钥已经发往您的手机 [ ' + phone +  ' ]，您将在几分钟后收到短信。\n您只需输入您收到的验证密钥即可完成手机绑定。如果您长时间未收到密钥，请尝试重新获取！' );
	}
	else if ( ret != '' )
	{
		showMessage ( ret );
	}
	else
	{
		showMessage ( '验证密钥发送失败，请稍候重试！' );
	}
}
//-->